/**
*  \file analog_controller.h
*
*  \brief
*
*  \author Michael J. Hohmann  michael.hohmann@linde-mh.de
*
*
*
*
*
*/
#ifndef ANALOG_CONTROLLER_H_INCLUDED
#define ANALOG_CONTROLLER_H_INCLUDED

/*================================================[ public includes  ]================================================*/
#include "../cfg/prj.h"
#include "../interpol/interpol_u16_s16.h"

/*================================================[ public defines   ]================================================*/

/*================================================[ public datatypes ]================================================*/

enum analog_controller_state
{
   analog_controller_state_wait_for_neutral,
   analog_controller_state_operational,
   analog_controller_state_error
};


/** Object definition.
* 
* The struct analog_controller_obj defines the attribute of an object.
*/
struct analog_controller_obj
{	
   U16 error_tolerance;
   U16 zero_tolerance;
   struct interpol_u16_s16_obj *ptable;
   enum analog_controller_state state;
   S16 current_value;

   U16 state_time;
};

/*================================================[ public variables ]================================================*/

/*================================================[ inline functions ]================================================*/

/*================================================[ public functions ]================================================*/

/**
*  Constructor.
*
*  Construct an object. 
*
*  \param [in,out] me Object pointer. NULL will throw an assert.
*  \param [in ] table pointer to the calibration curve
*  \param [in ] error_tolerance
*  \param [in ] zero_tolerance
*
*  \return RC_SUCCESS if successful.
*/
RC analog_controller_construct( struct analog_controller_obj *me, struct interpol_u16_s16_obj *ptable , U16 error_tolerance, U16 zero_tolerance );


/**
*  Process control values
*
*  \param [in ] me Object pointer. NULL will throw an assert.
*  \param [in ] value current value of the control
*
*/
void analog_controller_process( struct analog_controller_obj *me, F32 value1 , F32 value2, F32 reference );

/**
*  Constructor.
*
*  Construct an object.
*
*  \param [in ] me Object pointer. NULL will throw an assert.
*  \param [out] p_neutral pointer to store the neutral position.
*  \param [out] p_value pointer to store the value.
*
*  \return RC_SUCCESS if value is valid
*/
enum analog_controller_state analog_controller_get( struct analog_controller_obj const * me, S16 *p_neutral, S16 *p_value );


/*====================================================================================================================*/

#endif

/***********************************************************************************************************************
*                             Copyright 2019 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/
